from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Chrome(executable_path='../chromedriver.exe')

url = "https://www.lagou.com/"

driver.get(url)
time.sleep(1)
xpathQuanguo = '//*[@id="changeCityBox"]/p[1]/a'
el1  = driver.find_element(By.XPATH,xpathQuanguo)
el1.click()
time.sleep(2)
# 获得搜索输入框
xpathInput = "//input[@id='search_input']"
el2 = driver.find_element(By.XPATH,xpathInput)
# print(el2)
# # # 设置文本内容，键盘输入回车
el2.send_keys('python'+Keys.ENTER)
# #
time.sleep(1)
#
# # 获取到第一条职位的标题数据
a = driver.find_element(By.XPATH,'//*[@id="openWinPostion"]')
#
print(a.text)
a.click()
time.sleep(1)


#
# 转到新页面
# driver.window_handles 所有窗口的栈空间，从0到最后一个，最后-1
driver.switch_to.window(driver.window_handles[-1])
# # 获取职位描述信息
xpathStr = '//*[@id="job_detail"]/dd[2]/div'
# # 在详情页中，获取岗位需求详情
div = driver.find_element(By.XPATH,xpathStr)
print(div.text)

# 关闭当前活动窗口
driver.close()
# 跳转回去
driver.switch_to.window(driver.window_handles[0])
#
#
# time.sleep(11)
# driver.close()


# driver.switch_to.frame()
# driver.switch_to.parent_frame()


time.sleep(20)